﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using ThuPhap.Models;

namespace ThuPhap.ViewModels
{
    public class BackgroundOptionViewModel : BaseViewModel
    {
        public bool IsLoaded { get; set; }
        private ObservableCollection<BackgroundItem> item = null;

        public ObservableCollection<BackgroundItem> Items
        {
            get { return item; }
            private set { item = value; }
        }

        public BackgroundOptionViewModel()
        {
            this.Items = new ObservableCollection<BackgroundItem>();
            IsLoaded = false;
        }

        public void LoadBackground()
        {
            string background = "Background ";
            string template = "template";
            int total = 75;
            string name, description, image;
            for (int i = -1; i <= total; i++)
            {
                if (i == -1)
                {
                    name = "Background color";
                    description = "Color from color picker";
                    image = "Resources/Backgrounds/colorImage.png";
                }
                else if (i == 0)
                {
                    name = "Gallery image";
                    description = "Image from your gallery ";
                    image = "Resources/Backgrounds/gallery.png";
                }
                else
                {
                    int index = (i + 53) % 75;
                    if (index == 0)
                        index = 75;
                    name = background + " " + i.ToString();
                    description = background + template + " " + i.ToString();
                    image = "Resources/Backgrounds/background" + index.ToString() + ".jpg";
                }

                var item = new BackgroundItem()
                {
                    Name = name,
                    Description = description,
                    Image = image
                };

                Deployment.Current.Dispatcher.BeginInvoke(new AddBackgroundItemDelegate(AddBackgroundItem), item);
                
            }
            
            this.IsLoaded = true;
        }


        private delegate void AddBackgroundItemDelegate(BackgroundItem Background);
        private void AddBackgroundItem(BackgroundItem Background)
        {
            this.Items.Add(Background);
        }

    }
}
